package com.dong.ListNode.arithemtic;

import java.util.HashSet;
import java.util.Set;

/**
 * @author dcz
 * @classname GetIntersectionNode
 * @description 链表相交是否有节点
 * @date 2022/4/29 9:53
 */
public class GetIntersectionNode {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        Set<ListNode> nodeSet = new HashSet<>();
        ListNode temp = headA;
        while (temp != null){
            nodeSet.add(temp);
            temp = temp.next;
        }
        temp = headB;
        while (temp != null){
            if (nodeSet.contains(temp)){
                return temp;
            }
            temp = temp.next;
        }
        return null;
    }
}
